package servlets;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utility.UserSession;

public class MarketPlace extends HttpServlet{
	String message;
	int price;
public MarketPlace(){
	super();
	System.out.println("\n\n\n In Market place");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
	
        response.setContentType("text/html");
        String topic=request.getParameter("topicSelect");
        String[] subTopic=request.getParameterValues(topic);
        UserSession sess = new UserSession();
        //System.out.println("topic:"+topic);
        for(String s : subTopic){
        //System.out.println("subTopic"+s);
        price++;
        message=sess.addPurchasedQuiz(topic,s);
        }
        if(message.equals("Success"))
        {
       	 request.setAttribute("message", price);
       	RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/AddCreditCard.jsp");
        RequestDispatcherObj.forward(request, response);
        }
        else
        {
       	 request.setAttribute("message", message);
        }
}
}